2020-2021 Sunseeker Telemetry and Lighting System
rtc_a_ex1_calendermode.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
64 //******************************************************************************
65 
66 #include "driverlib.h"
67 
68 volatile Calendar newTime;
69 
70 void main (void)
71 {
72  Calendar currentTime;
73 
74  WDT_A_hold(WDT_A_BASE);
75 
76  //Set P1.0 to output direction
77  GPIO_setAsOutputPin(
78  GPIO_PORT_P1,
79  GPIO_PIN0
80  );
81 
82 
83  // Select XT1
84  GPIO_setAsPeripheralModuleFunctionInputPin(
85  GPIO_PORT_P5,
86  GPIO_PIN4 + GPIO_PIN5
87  );
88 
89 
90  //Initialize LFXT1
91  UCS_turnOnLFXT1(UCS_XT1_DRIVE_3,
92  UCS_XCAP_3
93  );
94 
95  //Setup Current Time for Calendar
96  currentTime.Seconds = 0x00;
97  currentTime.Minutes = 0x26;
98  currentTime.Hours = 0x13;
99  currentTime.DayOfWeek = 0x03;
100  currentTime.DayOfMonth = 0x20;
101  currentTime.Month = 0x07;
102  currentTime.Year = 0x2011;
103 
104  //Initialize Calendar Mode of RTC
105  /*
106  * Base Address of the RTC_A_A
107  * Pass in current time, intialized above
108  * Use BCD as Calendar Register Format
109  */
110  RTC_A_initCalendar(RTC_A_BASE,
111  &currentTime,
112  RTC_A_FORMAT_BCD);
113 
114  //Setup Calendar Alarm for 5:00pm on the 5th day of the week.
115  //Note: Does not specify day of the week.
116  RTC_A_configureCalendarAlarmParam param = {0};
117  param.minutesAlarm = 0x00;
118  param.hoursAlarm = 0x17;
119  param.dayOfWeekAlarm = RTC_A_ALARMCONDITION_OFF;
120  param.dayOfMonthAlarm = 0x05;
121  RTC_A_configureCalendarAlarm(RTC_A_BASE, &param);
122 
123  //Specify an interrupt to assert every minute
124  RTC_A_setCalendarEvent(RTC_A_BASE,
125  RTC_A_CALENDAREVENT_MINUTECHANGE);
126 
127  //Enable interrupt for RTC Ready Status, which asserts when the RTC
128  //Calendar registers are ready to read.
129  //Also, enable interrupts for the Calendar alarm and Calendar event.
130  RTC_A_clearInterrupt(RTC_A_BASE,
131  RTCRDYIFG + RTCTEVIFG + RTCAIFG);
132  RTC_A_enableInterrupt(RTC_A_BASE,
133  RTCRDYIE + RTCTEVIE + RTCAIE);
134 
135  //Start RTC Clock
136  RTC_A_startClock(RTC_A_BASE);
137 
138  //Enter LPM3 mode with interrupts enabled
139  __bis_SR_register(LPM3_bits + GIE);
140  __no_operation();
141 }
142 
143 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
144 #pragma vector=RTC_VECTOR
145 __interrupt
146 #elif defined(__GNUC__)
147 __attribute__((interrupt(RTC_VECTOR)))
148 #endif
149 void RTC_A_ISR (void)
150 {
151  switch (__even_in_range(RTCIV,16)){
152  case 0: break; //No interrupts
153  case 2: //RTCRDYIFG
154  //Toggle P1.0 every second
155  GPIO_toggleOutputOnPin(
156  GPIO_PORT_P1,
157  GPIO_PIN0);
158  break;
159  case 4: //RTCEVIFG
160  //Interrupts every minute
161  __no_operation();
162 
163  //Read out New Time a Minute Later BREAKPOINT HERE
164  newTime = RTC_A_getCalendarTime(RTC_A_BASE);
165  break;
166  case 6: //RTCAIFG
167  //Interrupts 5:00pm on 5th day of week
168  __no_operation();
169  break;
170  case 8: break; //RT0PSIFG
171  case 10: break; //RT1PSIFG
172  case 12: break; //Reserved
173  case 14: break; //Reserved
174  case 16: break; //Reserved
175  default: break;
176  }
177 }
178 
MPU_initThreeSegmentsParam param
__no_operation()
void main(void)
volatile Calendar newTime
void RTC_A_ISR(void)